package leetcode.二叉树;

import java.util.ArrayList;
import java.util.List;

public class 二叉树的所有路径257 {
    private static List<String> ans = new ArrayList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        ans.clear();
        if (root == null)
            return ans;
        process(root, "", ans);
        return ans;

    }

    private void process(TreeNode root, String cur, List<String> ans) {
        if (root == null)
            return;
        cur += root.val;
        if (root.left == null && root.right == null)
            ans.add(cur);
        else {
            process(root.left, cur + "->", ans);
            process(root.right, cur + "->", ans);
        }
    }
}
